package com.linux.huhx.thread3.lock_1;

import org.apache.commons.io.IOUtils;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: huhx
 * @Date: 2017-10-30 下午 5:34
 */
public class MyService {
    private Lock lock;

    public MyService(boolean isFair) {
        super();
        lock = new ReentrantLock(isFair);
    }

    public void serviceMethod() {
        try {
            lock.lock();
            System.out.println("name: " + Thread.currentThread().getName() + ", locked");
        } finally {
            lock.unlock();
        }
    }
}
